***** H1 - Children hypothesis

	* Produce Figure 1 - Predictive margins and marginal effects of living with parents on children’s level of satisfaction
	* with the economy or government’s performance
				
		clear all
		
		cd "${data}"	
		
			use data_ess.dta, clear 
		
				* Define significance stars
		graph set window fontface "Arial Narrow"
		global stars "+ 0.10 * 0.05 ** 0.01 *** 0.001"
		
				* Declare survey design for dataset
		svyset, clear 
		svyset country_code [weight=pspwght], strata(essround)
		
		
				* Economy (top panel)
				
	eststo clear
		
		eststo m1: svy: reg stfeco i.dummy_parents c.agea income i.unemployed education i.at_school i.essround i.country_code if agea<=34
		eststo m2: svy: reg stfeco i.dummy_parents c.agea income i.unemployed education unemployment_rate i.at_school i.essround i.country_code if agea<=34
		eststo m3: svy: reg stfeco i.dummy_parents##c.agea income i.unemployed education i.at_school i.essround i.country_code if agea<=34
		* Model 4:
		eststo Economy: svy: reg stfeco i.dummy_parents##c.agea income i.unemployed education i.at_school unemployment_rate i.essround i.country_code if agea<=34


		* Create the two margin plots
		
			quietly margins dummy_parents, at(agea=(18 (1) 34))
		
			
			marginsplot, recastci(rarea) ciopts(astyle(ci) acolor(%70)) plotopts(msymbol(i)) plot1opt(lpattern(dash))  ///
			title("Predictive Margins (95% CI)", size(4))  ///
			ytitle("Linear prediction", size(4)) yscale(r(3.5(0.5)5.5)) ylabel(3.5(0.5)5.5) xt(, size(4)) ///
			 scheme(lean1) legend(ring(0) pos(7)) ysize(1) xsize(1)  name(main) aspect(0.5)
			

			quietly margins, dydx(dummy_parents) at(agea=(18 (1) 34))
			
				
			marginsplot, recastci(rarea) ciopts(astyle(ci) acolor(%70)) plotopts(msymbol(i)) ///
			yscale(r(-0.75(0.25)0.75)) ylabel(-0.75(0.25)0.75)  yline(0, lwidth(thin) lpattern(dash) lcolor(black)) /// 
			yt(,size(4)) xt(, size(4))  scheme(lean1) /// 
			title("Average Marginal Effects of living with parents (95% CIs)", size(4)) ysize(1) xsize(1)  name(diff) aspect(0.5)
				
		* Now combine the plots together
			graph combine main diff, xsize(6.5) ysize(2.5) iscale(.8) title("{bf:ECONOMY}", size(4)) name(comb)
			graph close main diff
			graph export ${figures}/Figure1_top_economy.pdf, replace
			
			
			graph drop main diff comb 
			
			
				* Government (bottom panel)
				
		eststo m5: svy: reg stfgov i.dummy_parents c.agea income i.unemployed education i.at_school i.essround i.country_code if agea<=34
		eststo m6: svy: reg stfgov i.dummy_parents c.agea income i.unemployed education unemployment_rate i.at_school i.essround i.country_code if agea<=34
		eststo m7: svy: reg stfgov i.dummy_parents##c.agea income i.unemployed education i.at_school i.essround i.country_code if agea<=34
		* Model 8:
		eststo Government: svy: reg stfgov i.dummy_parents##c.agea income i.unemployed education i.at_school unemployment_rate i.essround i.country_code if agea<=34		

		* Create the two margin plots
		
			quietly margins dummy_parents, at(agea=(18 (1) 34))
			
			marginsplot, recastci(rarea) ciopts(astyle(ci) acolor(%70)) plotopts(msymbol(i)) plot1opt(lpattern(dash))  ///
			title("Predictive Margins (95% CI)", size(4))  ///
			ytitle("Linear prediction", size(4)) yscale(r(3.5(0.5)5.5)) ylabel(3.5(0.5)5.5) xt(, size(4)) ///
			 scheme(lean1) legend( ring(0) pos(7)) ysize(1) xsize(1)  name(main) aspect(0.5)

			quietly margins, dydx(dummy_parents) at(agea=(18 (1) 34))
			
			marginsplot, recastci(rarea) ciopts(astyle(ci) acolor(%70)) plotopts(msymbol(i)) ///
			yscale(r(-0.75(0.25)0.75))  ylabel(-0.75(0.25)0.75)  yline(0, lwidth(thin) lpattern(dash) lcolor(black)) /// 
			yt(,size(4)) xt(, size(4))  scheme(lean1) /// 
			title("Average Marginal Effects of living with parents (95% CIs)", size(4)) ysize(1) xsize(1)  name(diff) aspect(0.5)
				
			* Now combining the plots together
			
			graph combine main diff, xsize(6.5) ysize(2.5) iscale(.8) title("{bf:GOVERNMENT}") name(comb)
			graph close main diff
			graph export ${figures}/Figure1_bottom_government.pdf, replace
			
			
			graph drop main diff comb 
			
			
			*** Appendix H - Main model - Full Table - Children hypothesis - DV: Economy
				
	esttab m1 m2 m3 Economy using ${tables}/appendixH.tex, ///
			nomtitles booktabs replace ///
			indicate("Country FE = *.country_code" "Year FE = *.essround", labels("\checkmark" "")) ///
			stats(N r2, fmt(%9.0fc %9.2fc)  labels("Observations" "R-squared")) ///
			nobaselevels interaction("\$\times\$") substitute("=1" "") nogap compress nonotes b(2) se(2) starlevels( ${stars}) ///
			label mlabels("Model 1" "Model 2" "Model 3" "Model 4") 
			
			*** Appendix I - Main model - Full Table - Children hypothesis - DV: Government 

	esttab m5 m6 m7 Government using ${tables}/appendixI.tex, ///
			nomtitles booktabs replace ///
			indicate("Country FE = *.country_code" "Year FE = *.essround", labels("\checkmark" "")) ///
			stats(N r2, fmt(%9.0fc %9.2fc)  labels("Observations" "R-squared")) ///
			nobaselevels interaction("\$\times\$") substitute("=1" "") nogap compress nonotes b(2) se(2) starlevels( ${stars}) ///
			label mlabels("Model 5" "Model 6" "Model 7" "Model 8") 
			
			

			
			
